/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JRentEditor.java
 *
 * Created on 2009-8-2, 9:26:21
 */

package cn.ekuma.epos.rant;

import cn.ekuma.data.ui.swing.SwingEditorRecord;
import cn.ekuma.epos.businesslogic.RantUtil;
import cn.ekuma.epos.datalogic.I_DataLogicCustomers;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import com.openbravo.data.basic.BasicException;
import com.openbravo.beans.JCalendarDialog;
import com.openbravo.data.gui.ComboBoxValEntry;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.format.Formats;

import com.openbravo.bean.infobean.CustomerInfo;
import com.openbravo.bean.Product;
import com.openbravo.bean.Rant;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.panels.JCustomerFinder;
import com.openbravo.pos.panels.JProductAttEdit;
import com.openbravo.pos.panels.JProductFinder;

import java.awt.Component;
import java.awt.Toolkit;
import java.util.Date;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sourceforge.jtimepiece.TimeUtil;

/**
 * @author Administrator
 */
public class JRentEditor extends javax.swing.JPanel implements SwingEditorRecord {
    private final DirtyManager m_dirty;
    private final I_DataLogicSales m_dlSales;
    private Product product;
    private CustomerInfo customer;
    private JRentFilter filter;
    private final I_DataLogicCustomers dlCustomers;
    private ComboBoxValModel rantCycleStyleModel;
    private Rant currentRant;
    private final JRentPanel jRentPanel;


    /**
     * Creates new form JRentEditor
     */
    public JRentEditor(JRentPanel panel) {
        initComponents();
        m_dlSales = panel.getM_dlSales();
        this.m_dirty = panel.getDirty();
        this.filter = panel.getjRantFilter();
        dlCustomers = panel.getDlCustomers();
        currentRant = null;
        jRentPanel = panel;

        rantCycleStyleModel = new ComboBoxValModel();
        rantCycleStyleModel.add(new ComboBoxValEntry(Rant.RANTCYCLESTYLE_everyDay, AppLocal.getIntString("list.RANTCYCLESTYLE_everyDay")));
        rantCycleStyleModel.add(new ComboBoxValEntry(Rant.RANTCYCLESTYLE_everyWeek, AppLocal.getIntString("list.RANTCYCLESTYLE_everyWeek")));
        //rantCycleStyleModel.add(new ComboBoxValEntry(Rant.RANTCYCLESTYLE_halfmoon,AppLocal.getIntString("list.RANTCYCLESTYLE_halfmoon")));
        rantCycleStyleModel.add(new ComboBoxValEntry(Rant.RANTCYCLESTYLE_moon, AppLocal.getIntString("list.RANTCYCLESTYLE_moon")));
        //rantCycleStyleModel.add(new ComboBoxValEntry(Rant.RANTCYCLESTYLE_halfyear,AppLocal.getIntString("list.RANTCYCLESTYLE_halfyear")));
        rantCycleStyleModel.add(new ComboBoxValEntry(Rant.RANTCYCLESTYLE_year, AppLocal.getIntString("list.RANTCYCLESTYLE_year")));
        jrantCycleStyle.setModel(rantCycleStyleModel);


        jrantPrice.getDocument().addDocumentListener(m_dirty);
        jexemptDate.getDocument().addDocumentListener(m_dirty);
        jcyclePrice.getDocument().addDocumentListener(m_dirty);
        jcustomDate.getDocument().addDocumentListener(m_dirty);

        jrantData.getDocument().addDocumentListener(m_dirty);
        m_jbtndate.addActionListener(m_dirty);

        jpriceRate.getDocument().addDocumentListener(m_dirty);

        jmemo.getDocument().addDocumentListener(m_dirty);
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jEditProduct = new javax.swing.JButton();
        jEditAttributes = new javax.swing.JButton();
        m_jcodebar = new javax.swing.JTextField();
        jattributes = new javax.swing.JTextField();
        jproduct = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        m_jreference = new javax.swing.JTextField();
        m_jEnter1 = new javax.swing.JButton();
        m_jEnter = new javax.swing.JButton();
        jCustomerName = new javax.swing.JTextField();
        jcustomer = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jm_dStopDateLabel = new javax.swing.JLabel();
        m_jbtndate = new javax.swing.JButton();
        jrantData = new javax.swing.JTextField();
        jm_dStartDateLabel = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jcyclePrice = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jexemptDate = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jrantCycleStyle = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jcustomDate = new javax.swing.JTextField();
        jreturnData = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jdateCount = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jpriceRate = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jrantPrice = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jcountPrice = new javax.swing.JTextField();
        jrantState = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jmemo = new javax.swing.JTextArea();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));

        jLabel6.setText(AppLocal.getIntString("label.stockproduct")); // NOI18N

        jLabel11.setText(AppLocal.getIntString("label.attributes")); // NOI18N

        jEditProduct.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/search.png"))); // NOI18N
        jEditProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jEditProductActionPerformed(evt);
            }
        });

        jEditAttributes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/colorize16.png"))); // NOI18N
        jEditAttributes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jEditAttributesActionPerformed(evt);
            }
        });

        m_jcodebar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jcodebarActionPerformed(evt);
            }
        });

        jattributes.setEditable(false);

        jproduct.setEditable(false);

        jLabel7.setText(AppLocal.getIntString("label.prodbarcode")); // NOI18N

        jLabel12.setText(AppLocal.getIntString("label.prodref")); // NOI18N

        m_jreference.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jreferenceActionPerformed(evt);
            }
        });

        m_jEnter1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jEnter1.setFocusPainted(false);
        m_jEnter1.setFocusable(false);
        m_jEnter1.setRequestFocusEnabled(false);
        m_jEnter1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jEnter1ActionPerformed(evt);
            }
        });

        m_jEnter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jEnter.setFocusPainted(false);
        m_jEnter.setFocusable(false);
        m_jEnter.setRequestFocusEnabled(false);
        m_jEnter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jEnterActionPerformed(evt);
            }
        });

        jCustomerName.setEditable(false);

        jcustomer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/kuser.png"))); // NOI18N
        jcustomer.setFocusPainted(false);
        jcustomer.setFocusable(false);
        jcustomer.setMargin(new java.awt.Insets(8, 14, 8, 14));
        jcustomer.setRequestFocusEnabled(false);
        jcustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcustomerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(m_jreference, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(10, 10, 10)
                                                .addComponent(m_jEnter1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jattributes, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                                                .addComponent(jEditAttributes, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addGap(150, 150, 150)
                                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(m_jcodebar, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(10, 10, 10)
                                                                .addComponent(m_jEnter, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                                .addComponent(jproduct, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(10, 10, 10)
                                                                .addComponent(jEditProduct, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addGap(28, 28, 28)
                                                .addComponent(jcustomer)
                                                .addGap(38, 38, 38)))
                                .addGap(120, 120, 120))
        );
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel6)
                                        .addComponent(jLabel12)
                                        .addComponent(m_jreference, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(m_jEnter1))
                                .addGap(6, 6, 6)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel7)
                                                        .addComponent(m_jcodebar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(m_jEnter))
                                                .addGap(6, 6, 6)
                                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jproduct, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(jEditProduct)))
                                        .addComponent(jcustomer))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel11)
                                        .addComponent(jattributes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jEditAttributes))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(jPanel2);

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jm_dStopDateLabel.setText(AppLocal.getIntString("label.returnData")); // NOI18N

        m_jbtndate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/date.png"))); // NOI18N
        m_jbtndate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jbtndateActionPerformed(evt);
            }
        });

        jm_dStartDateLabel.setText(AppLocal.getIntString("label.rantData")); // NOI18N

        jLabel3.setText(AppLocal.getIntString("label.cyclePrice")); // NOI18N

        jcyclePrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jcyclePrice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcyclePriceActionPerformed(evt);
            }
        });

        jLabel2.setText(AppLocal.getIntString("label.exemptDate")); // NOI18N

        jexemptDate.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jexemptDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jexemptDateActionPerformed(evt);
            }
        });

        jLabel8.setText(AppLocal.getIntString("label.rantCycleStyle")); // NOI18N

        jrantCycleStyle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrantCycleStyleActionPerformed(evt);
            }
        });

        jLabel5.setText(AppLocal.getIntString("label.customDate")); // NOI18N

        jcustomDate.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jreturnData.setEditable(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jm_dStartDateLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addComponent(jrantData, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(6, 6, 6)
                                                .addComponent(m_jbtndate, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jm_dStopDateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addComponent(jcyclePrice, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addComponent(jexemptDate, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(jcustomDate, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jrantCycleStyle, javax.swing.GroupLayout.Alignment.LEADING, 0, 124, Short.MAX_VALUE))
                                        .addComponent(jreturnData, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(46, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel2)
                                        .addComponent(jexemptDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel8)
                                        .addComponent(jrantCycleStyle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(8, 8, 8)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel3)
                                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jcyclePrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel5)
                                                .addComponent(jcustomDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                        .addComponent(jm_dStartDateLabel)
                                        .addComponent(jrantData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(m_jbtndate)
                                        .addComponent(jm_dStopDateLabel)
                                        .addComponent(jreturnData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(jPanel3);

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel4.setText(AppLocal.getIntString("label.dateCount")); // NOI18N

        jdateCount.setEditable(false);
        jdateCount.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel10.setText(AppLocal.getIntString("label.prefRate")); // NOI18N

        jpriceRate.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jpriceRate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jpriceRateActionPerformed(evt);
            }
        });

        jLabel1.setText(AppLocal.getIntString("label.rantPrice")); // NOI18N

        jrantPrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jdateCount, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jpriceRate, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrantPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(73, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel4)
                                        .addComponent(jdateCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel10)
                                        .addComponent(jpriceRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1)
                                        .addComponent(jrantPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(jPanel4);

        jLabel9.setFont(new java.awt.Font("宋体", 1, 24));
        jLabel9.setText(AppLocal.getIntString("label.subtotalcash")); // NOI18N

        jcountPrice.setEditable(false);
        jcountPrice.setFont(new java.awt.Font("宋体", 0, 24));
        jcountPrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jrantState.setText("付款");
        jrantState.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrantStateActionPerformed(evt);
            }
        });

        jmemo.setColumns(20);
        jmemo.setRows(5);
        jScrollPane2.setViewportView(jmemo);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcountPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrantState, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jrantState, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jcountPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(jLabel9))))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(jPanel1);
    }// </editor-fold>//GEN-END:initComponents


    private void assignProductByReference() {
        try {
            Product prod = m_dlSales.getProductInfoByReference(m_jreference.getText());
            if (prod == null) {
                Toolkit.getDefaultToolkit().beep();
            }
            assignProduct(prod);
            m_dirty.setDirty(true);
        } catch (BasicException eData) {
            MessageInf msg = new MessageInf(eData);
            msg.show(this);
            assignProduct(null);
        }
    }

    private void assignProductByCode() {
        /**try {
         Product prod = m_dlSales.getProductInfoByCode(m_jcodebar.getText());
         if (prod == null) {
         Toolkit.getDefaultToolkit().beep();
         }
         assignProduct(prod);
         m_dirty.setDirty(true);
         } catch (BasicException eData) {
         MessageInf msg = new MessageInf(eData);
         msg.show(this);
         assignProduct(null);
         }*/
    }

    private void assignProduct(Product prod) {
        product = prod;
        if (product == null) {
            jproduct.setText(null);
            m_jcodebar.setText(null);
            m_jreference.setText(null);
            currentRant.setM_sId(null);
            currentRant.setAttributeSetid(null);
            jattributes.setText(null);
        } else {
            jproduct.setText(product.getReference() + " - " + product.getName());
            m_jcodebar.setText(product.getCode());
            m_jreference.setText(product.getReference());
            currentRant.setM_sId(product.getID());
            currentRant.setAttributeSetid(null);
            jattributes.setText(null);
        }
    }


    private void m_jbtndateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jbtndateActionPerformed

        Date date;
        try {
            date = (Date) Formats.TIMESTAMP.parseValue(jrantData.getText());
        } catch (BasicException e) {
            date = null;
        }
        date = JCalendarDialog.showCalendarTime(this, date);
        if (date != null) {
            if (date.after(new Date())) {
                MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("mess.rant.mustbefore"));
                msg.show(this);
            } else
                jrantData.setText(Formats.TIMESTAMP.formatValue(date));
        }
    }//GEN-LAST:event_m_jbtndateActionPerformed

    private void m_jcodebarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jcodebarActionPerformed

        assignProductByCode();
    }//GEN-LAST:event_m_jcodebarActionPerformed

    private void jEditAttributesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jEditAttributesActionPerformed

        if (product == null) {
            // first select the product.
            MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.productnotselected"));
            msg.show(this);
        } else {
            try {
                JProductAttEdit attedit = JProductAttEdit.getAttributesEditor(this, m_dlSales);
                attedit.editAttributes(product.getAttributeSetID(), this.jattributes.getText(), null);
                attedit.setVisible(true);

                if (attedit.isOK()) {
                    // The user pressed OK
                    currentRant.setAttributeSetid(attedit.getAttributeSetInstance().getId());
                    jattributes.setText(attedit.getAttributeSetInstance().getId());
                }
            } catch (BasicException ex) {
                MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindattributes"), ex);
                msg.show(this);
            }
        }
    }//GEN-LAST:event_jEditAttributesActionPerformed

    private void jEditProductActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jEditProductActionPerformed

        assignProduct(JProductFinder.showMessage(this, m_dlSales));
    }//GEN-LAST:event_jEditProductActionPerformed

    private void m_jreferenceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jreferenceActionPerformed

        assignProductByReference();
    }//GEN-LAST:event_m_jreferenceActionPerformed

    private void m_jEnter1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jEnter1ActionPerformed

        assignProductByReference();
    }//GEN-LAST:event_m_jEnter1ActionPerformed

    private void m_jEnterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jEnterActionPerformed

        assignProductByCode();
    }//GEN-LAST:event_m_jEnterActionPerformed

    private void jrantStateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrantStateActionPerformed
        changeRantState();
    }//GEN-LAST:event_jrantStateActionPerformed

    private void jpriceRateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jpriceRateActionPerformed
        calcSubTotal();
    }//GEN-LAST:event_jpriceRateActionPerformed

    private void jcyclePriceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcyclePriceActionPerformed
        calcSubTotal();
    }//GEN-LAST:event_jcyclePriceActionPerformed

    private void jrantCycleStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrantCycleStyleActionPerformed
        calcSubTotal();
    }//GEN-LAST:event_jrantCycleStyleActionPerformed

    private void jexemptDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jexemptDateActionPerformed
        calcSubTotal();
    }//GEN-LAST:event_jexemptDateActionPerformed

    private void jcustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcustomerActionPerformed
        assignCustomer();
    }//GEN-LAST:event_jcustomerActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField jCustomerName;
    private javax.swing.JButton jEditAttributes;
    private javax.swing.JButton jEditProduct;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jattributes;
    private javax.swing.JTextField jcountPrice;
    private javax.swing.JTextField jcustomDate;
    private javax.swing.JButton jcustomer;
    private javax.swing.JTextField jcyclePrice;
    private javax.swing.JTextField jdateCount;
    private javax.swing.JTextField jexemptDate;
    private javax.swing.JLabel jm_dStartDateLabel;
    private javax.swing.JLabel jm_dStopDateLabel;
    private javax.swing.JTextArea jmemo;
    private javax.swing.JTextField jpriceRate;
    private javax.swing.JTextField jproduct;
    private javax.swing.JComboBox jrantCycleStyle;
    private javax.swing.JTextField jrantData;
    private javax.swing.JTextField jrantPrice;
    private javax.swing.JButton jrantState;
    private javax.swing.JTextField jreturnData;
    private javax.swing.JButton m_jEnter;
    private javax.swing.JButton m_jEnter1;
    private javax.swing.JButton m_jbtndate;
    private javax.swing.JTextField m_jcodebar;
    private javax.swing.JTextField m_jreference;
    // End of variables declaration//GEN-END:variables

    @Override
    public void writeValueEOF() {
        setAllDesable();
        customer = null;
        product = null;
        currentRant = null;

        m_jreference.setText(null);
        m_jcodebar.setText(null);
        jattributes.setText(null);
        jproduct.setText(null);

        jrantPrice.setText(null);
        jexemptDate.setText(null);
        jcustomer.setText(null);
        jcyclePrice.setText(null);
        jcustomDate.setText(null);

        jrantData.setText(null);
        jreturnData.setText(null);

        jdateCount.setText(null);
        jcountPrice.setText(null);

        jpriceRate.setText(null);

        jmemo.setText(null);
        jrantState.setText(null);
    }

    @Override
    public void writeValueInsert(Properties prop) {
        setAllable();

        this.product = null;
        currentRant = new Rant();
        customer = filter.getCustomerInfo();
        assignCustomer(customer);

        m_jreference.setText(null);
        m_jcodebar.setText(null);
        jproduct.setText(null);
        jattributes.setText(null);


        jrantPrice.setText(Formats.CURRENCY.formatValue(currentRant.getRantPrice()));
        jexemptDate.setText(Formats.INT.formatValue(currentRant.getExemptDate()));

        jcyclePrice.setText(Formats.CURRENCY.formatValue(currentRant.getCyclePrice()));

        jcustomDate.setText(Formats.INT.formatValue(currentRant.getCustomDate()));

        jrantData.setText(Formats.TIMESTAMP.formatValue(currentRant.getRantData()));
        if (currentRant.getReturnData() != null)
            jreturnData.setText(Formats.TIMESTAMP.formatValue(currentRant.getReturnData()));
        else
            jreturnData.setText(null);

        jpriceRate.setText(Formats.PERCENT.formatValue(currentRant.getPriceRate()));

        jmemo.setText(null);
        jdateCount.setText(Formats.INT.formatValue(0));
        jcountPrice.setText(Formats.CURRENCY.formatValue(0));

        rantCycleStyleModel.setSelectedKey(currentRant.getRantCycleStyle());

        checkRantState(currentRant);
    }

    @Override
    public void writeValueEdit(Object value) {
        if (value instanceof Rant)
            writeValueEdit((Rant) value);
        else
            writeValueEdit(creatRant((Object[]) value));
    }

    Rant creatRant(Object[] prop) {
        Rant temp = new Rant();
        temp.setId((String) prop[0]);
        temp.setM_sId((String) prop[1]);
        temp.setAttributeSetid((String) prop[2]);
        temp.setCustomerid((String) prop[3]);
        temp.setRantPrice((Double) prop[4]);
        temp.setRantCycleStyle((String) prop[5]);
        temp.setCustomDate((Integer) prop[6]);
        temp.setCyclePrice((Double) prop[7]);
        temp.setExemptDate((Integer) prop[8]);
        temp.setPriceRate((Double) prop[9]);
        temp.setRantData((Date) prop[10]);
        temp.setReturnData((Date) prop[11]);
        temp.setMemo((String) prop[12]);
        temp.setRantState((String) prop[13]);
        return temp;
    }


    void writeValueEdit(Rant value) {
        currentRant = (Rant) value;
        checkRantState(currentRant);

        try {
            Product prod = m_dlSales.getProductInfo(currentRant.getM_sId());
            if (prod == null) {
                Toolkit.getDefaultToolkit().beep();
            }
            assignProduct(prod);
        } catch (BasicException eData) {
            MessageInf msg = new MessageInf(eData);
            msg.show(this);
            assignProduct(null);
        }

        if (currentRant.getCustomerid() != null && !currentRant.getCustomerid().isEmpty()) {
            try {
                CustomerInfo custom = dlCustomers.findCustomerInfoByID(currentRant.getCustomerid(), null);
                assignCustomer(custom);
            } catch (BasicException ex) {
                MessageInf msg = new MessageInf(ex);
                msg.show(this);
                assignCustomer(null);
            }
        }

        jrantPrice.setText(Formats.CURRENCY.formatValue(currentRant.getRantPrice()));
        jexemptDate.setText(Formats.INT.formatValue(currentRant.getExemptDate()));

        jcyclePrice.setText(Formats.CURRENCY.formatValue(currentRant.getCyclePrice()));

        jcustomDate.setText(Formats.INT.formatValue(currentRant.getCustomDate()));

        jrantData.setText(Formats.TIMESTAMP.formatValue(currentRant.getRantData()));
        if (currentRant.getReturnData() != null)
            jreturnData.setText(Formats.TIMESTAMP.formatValue(currentRant.getReturnData()));
        else
            jreturnData.setText(null);

        jpriceRate.setText(Formats.PERCENT.formatValue(currentRant.getPriceRate()));
        jmemo.setText(currentRant.getMemo());

        rantCycleStyleModel.setSelectedKey(currentRant.getRantCycleStyle());

        calcSubTotal();
    }

    private void assignCustomer() {
        JCustomerFinder customerFinder = JCustomerFinder.getCustomerFinder(this, m_dlSales);
        if (customer != null)
            customerFinder.search(customer);
        customerFinder.setVisible(true);
        assignCustomer(customerFinder.getSelectedCustomer());
    }


    public void checkRantState(Rant rant) {
        if (Rant.RANTSTATE_noRant.equalsIgnoreCase(rant.getRantState())) {
            setAllable();
            jrantState.setText(AppLocal.getIntString("list.RANTSTATE_noRant"));
        } else if (Rant.RANTSTATE_rant.equalsIgnoreCase(rant.getRantState())) {
            setAllDesable();
            jpriceRate.setEnabled(true);
            jmemo.setEnabled(true);
            jrantState.setEnabled(true);
            jrantState.setText(AppLocal.getIntString("list.RANTSTATE_rant"));
        } else if (Rant.RANTSTATE_returned.equalsIgnoreCase(rant.getRantState())) {
            setAllDesable();
            jrantState.setText(AppLocal.getIntString("list.RANTSTATE_returned"));
        }
    }

    @Override
    public void writeValueDelete(Object value) {
        if (value instanceof Rant)
            writeValueEdit((Rant) value);
        else
            writeValueEdit(creatRant((Object[]) value));

        setAllDesable();
    }

    private void setAllable() {
        m_jreference.setEnabled(true);
        m_jEnter1.setEnabled(true);
        m_jcodebar.setEnabled(true);
        m_jEnter.setEnabled(true);
        jEditProduct.setEnabled(true);

        jEditAttributes.setEnabled(true);

        jrantPrice.setEnabled(true);
        jexemptDate.setEnabled(true);
        jcustomer.setEnabled(true);
        jcyclePrice.setEnabled(true);
        jrantCycleStyle.setEnabled(true);
        jcustomDate.setEnabled(true);

        jrantData.setEnabled(true);
        m_jbtndate.setEnabled(true);
        jreturnData.setEnabled(true);

        jpriceRate.setEnabled(true);

        jmemo.setEnabled(true);
        jrantState.setEnabled(true);

    }

    private void setAllDesable() {
        //products
        m_jreference.setEnabled(false);
        m_jEnter1.setEnabled(false);
        m_jcodebar.setEnabled(false);
        m_jEnter.setEnabled(false);
        jEditProduct.setEnabled(false);

        jEditAttributes.setEnabled(false);

        jrantPrice.setEnabled(false);
        jexemptDate.setEnabled(false);
        jcustomer.setEnabled(false);
        jcyclePrice.setEnabled(false);
        jrantCycleStyle.setEnabled(false);
        jcustomDate.setEnabled(false);

        jrantData.setEnabled(false);
        m_jbtndate.setEnabled(false);
        jreturnData.setEnabled(false);

        jpriceRate.setEnabled(false);

        jmemo.setEnabled(false);
        jrantState.setEnabled(false);

    }

    @Override
    public void refresh() {
    }

    @Override
    public Component getComponent() {
        return this;
    }

    @Override
    public Object createValue() throws BasicException {
        Object[] prop = new Object[14];
        prop[0] = currentRant.getId();
        prop[1] = currentRant.getM_sId();
        prop[2] = currentRant.getAttributeSetid();
        prop[3] = currentRant.getCustomerid();
        prop[4] = Formats.CURRENCY.parseValue(jrantPrice.getText(), 0);
        prop[5] = rantCycleStyleModel.getSelectedKey();
        prop[6] = Formats.INT.parseValue(jcustomDate.getText(), 0);
        prop[7] = Formats.CURRENCY.parseValue(this.jcyclePrice.getText(), 0);
        prop[8] = Formats.INT.parseValue(this.jexemptDate.getText(), 0);
        prop[9] = Formats.PERCENT.parseValue(this.jpriceRate.getText(), 0);
        prop[10] = Formats.TIMESTAMP.parseValue(this.jrantData.getText());
        prop[11] = currentRant.getReturnData();
        prop[12] = jmemo.getText();
        prop[13] = currentRant.getRantState();
        return prop;
    }

    private void assignCustomer(CustomerInfo selectedCustomer) {
        if (selectedCustomer != null) {
            jCustomerName.setText(selectedCustomer.getName());
            currentRant.setCustomerid(selectedCustomer.getId());
        } else {
            jCustomerName.setText(null);
            currentRant.setCustomerid(null);
        }
    }

    private void changeRantState() {
        String cState = this.currentRant.getRantState();
        if (!RantUtil.isRantStateChangeAble(m_dlSales, currentRant, cState))
            return;
        RantUtil.changeRantState(m_dlSales, currentRant, cState);
        m_dirty.setDirty(true);
        checkRantState(currentRant);
        if (Rant.RANTSTATE_noRant.equalsIgnoreCase(cState)) {
            RantUtil.changeRantState(m_dlSales, currentRant, cState);
            m_dirty.setDirty(true);
            checkRantState(currentRant);
        } else if (Rant.RANTSTATE_rant.equalsIgnoreCase(cState)) {
            RantUtil.changeRantState(m_dlSales, currentRant, cState);
            m_dirty.setDirty(true);
            checkRantState(currentRant);
        }
        try {
            jRentPanel.saveData();
        } catch (BasicException ex) {
            Logger.getLogger(JRentEditor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void calcSubTotal() {
        try {
            String rantCycleStyle = (String) rantCycleStyleModel.getSelectedKey();
            int customDate = (Integer) Formats.INT.parseValue(jcustomDate.getText(), 0);
            int exemptDate = (Integer) Formats.INT.parseValue(this.jexemptDate.getText(), 0);
            double cyclePrice = (Double) Formats.CURRENCY.parseValue(this.jcyclePrice.getText(), 0);
            double priceRate = (Double) Formats.PERCENT.parseValue(this.jpriceRate.getText(), 0);
            Date returndate = this.currentRant.getReturnData();
            if (returndate == null) {
                returndate = new Date();
            }
            double subTotal = 0;
            int subDays = 0;
            int rangDays = 0;
            if (Rant.RANTCYCLESTYLE_everyDay.equalsIgnoreCase(rantCycleStyle)) {
                rangDays = TimeUtil.getCalendarDaysAfter(currentRant.getRantData(), returndate);
                subDays = rangDays - exemptDate;
                if (customDate > 0) {
                    subDays = subDays / customDate;
                }
            } else if (Rant.RANTCYCLESTYLE_everyWeek.equalsIgnoreCase(rantCycleStyle)) {
            } else if (Rant.RANTCYCLESTYLE_moon.equalsIgnoreCase(rantCycleStyle)) {
                rangDays = TimeUtil.getCalendarMonthsAfter(currentRant.getRantData(), returndate);
                subDays = rangDays - exemptDate;
            } else if (Rant.RANTCYCLESTYLE_year.equalsIgnoreCase(rantCycleStyle)) {
                rangDays = TimeUtil.getCalendarYearsAfter(currentRant.getRantData(), returndate);
                subDays = rangDays - exemptDate;
            }
            subTotal = subDays * cyclePrice * (1 - priceRate);
            jdateCount.setText(Formats.INT.formatValue(subDays));
            jcountPrice.setText(Formats.CURRENCY.formatValue(subTotal));
        } catch (BasicException ex) {
            MessageInf msg = new MessageInf(ex);
            msg.show(this);
            jdateCount.setText(Formats.INT.formatValue(0));
            jcountPrice.setText(Formats.CURRENCY.formatValue(0));
        }
    }

    @Override
    public void activate() throws BasicException {
        // TODO Auto-generated method stub

    }

    @Override
    public String getLogerString() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean isLogAble() {
        // TODO Auto-generated method stub
        return false;
    }

}
